package com.apes.framework.plugin.soe.metadata;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：场景角色（单据流）
 *
 * @author xul
 * @create 2018-09-21 11:45
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SceneInstanceRole.CONST_TABLE_NAME, indexes = {
        @Index(name = "idx_scene_inst_role", columnList = "scene_id, business_type, business_key", unique = true)})
public class SceneInstanceRole extends BaseModel {
    public static final String CONST_TABLE_NAME = "soe_scene_inst_role";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "场景角色实例")
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "scene_inst_id", referencedColumnName = "id", nullable = false)
    @Comment("场景实例")
    private SceneInstance sceneInstance;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "scene_id", referencedColumnName = "id", nullable = false)
    @Comment("场景")
    private Scene scene;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "business_type", referencedColumnName = "id", nullable = false)
    @Comment("凭证类型")
    private BusinessType businessType;

    @Column(name = "business_key", length = 32, nullable = false)
    @Comment("凭证编号")
    private String businessKey;

}
